package com.framework.bas.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

@SuppressWarnings("unused")
public class CharacterEncodingFilter implements Filter {

	private FilterConfig _fldif;
    private String encoding;

    public CharacterEncodingFilter() {
        _fldif = null;
        encoding = "ASCII";
    }

    public void init(FilterConfig filterconfig) throws ServletException {
        _fldif = filterconfig;
        encoding = filterconfig.getInitParameter("encoding");
    }

    public void destroy() {
        _fldif = null;
        encoding = null;
    }

    public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, 
    		FilterChain filterchain) throws IOException, ServletException {
        HttpServletRequest httpservletrequest = (HttpServletRequest)servletrequest;
        httpservletrequest.setCharacterEncoding(encoding);
        filterchain.doFilter(servletrequest, servletresponse);
    }

}
